package com.wj.taobaoke;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.util.List;
import java.util.Random;

public class AnalysistAlimamaSearchResult {

	
	private AnalysisWeb analysisWeb = new AnalysisWeb();
	
	public static void main(String[] args) {
		args = new String[9];
		args[0] = "http://s.click.taobao.com/t_8?e=7HZ6jHSTbIbg0og2fr8Hx8nmwNHsIxQECQDXNn%2BKet7mwA%3D%3D&p=mm_17818995_0_0";
		args[1] = "http://s.click.taobao.com/t_8?e=7HZ6jHSTbIWe3PqxIyPEuS8YJX3OsJGkfZO88HIvxHNkqg%3D%3D&p=mm_17818995_0_0";
		args[2] = "http://s.click.taobao.com/t_8?e=7HZ6jHSTbIg11dZ9CoGfOV0KbQRuIoNodyPyY%2FKwFizkkQ%3D%3D&p=mm_17818995_0_0";
		args[3] = "http://s.click.taobao.com/t_8?e=7HZ6jHSTbIlJ046fb%2BdMGuvaLmlamZfU1YfpLqHQZ6SjAQ%3D%3D&p=mm_17818995_0_0";
		args[4] = "http://s.click.taobao.com/t_8?e=7HZ6jHSTbIOeOZx7Gf9V5ded2pJpeX7zRm7JOTx%2FSxa5wQ%3D%3D&p=mm_17818995_0_0";
		args[5] = "http://s.click.taobao.com/t_8?e=7HZ6jHSTbIbg1KpoRrAWmHskWtsnHqeJcsl52sdYAHdtAQ%3D%3D&p=mm_17818995_0_0";
		args[6] = "http://s.click.taobao.com/t_8?e=7HZ6jHSTbIbkoYliUSHAIb8ToPXDcMp1WuUR%2FZI2ADFxHQ%3D%3D&p=mm_17818995_0_0";
		
		Random random = new Random();
		AnalysisWeb analysisWeb = new AnalysisWeb();
		String htmlurl = "e:\\merchandisePromotion.htm";
		String html = analysisWeb.getOneFile(htmlurl, "GBK");
		String regex = "<tbody>(.*?)</tbody>";
		String goodsStr = analysisWeb.getForRegex(html, regex);
		regex = "<tr(.*?)</tr>";
		List<String> goodsList = analysisWeb.getContentListFroRegex(goodsStr, regex);
		GenerateGoodsFile generateGoodsFile = new GenerateGoodsFile(null, null);
		GoodsItem goodsItem = null;
		regex = "<td(.*?)</td>";
		int goodsIndex = 0;
		for (String string : goodsList) {
			goodsItem = new GoodsItem();
			goodsItem.itemUrl = args[goodsIndex];
			goodsIndex++;
			goodsItem.index = goodsIndex;
			List<String> oneGoodsList = analysisWeb.getContentListFroRegex(string, regex);
			int index = 0;
			for (String string2 : oneGoodsList) {
				index++;
				if(index == 1){
					goodsItem.itemPic = analysisWeb.getForRegex(string2, "http://img(.*?)_sum.jpg");
					goodsItem.itemName = analysisWeb.outTag(analysisWeb.getForRegex(string2, "<img src=(.*?)<p class=\"shopkeeper\">")).trim();
				}else if(index == 2){
					goodsItem.itemPrice = analysisWeb.outTag(string2).replace("元", "");
				}else if(index == 5){
					int num = Integer.parseInt(analysisWeb.outTag(string2).replace("件", ""));
					num = num + random.nextInt(100);
					num = num + random.nextInt(100);
					num = num + random.nextInt(100);
					goodsItem.itemComment = ""+num;
				}
			}
			System.out.println(generateGoodsFile.generateOneGoodsItemHtml(goodsItem).toString());
		}
	}
}
